package at.fhv.framework.filter;

import at.fhv.framework.interfaces.Pull;
import at.fhv.framework.interfaces.Push;

/**
 * @author Michael
 * @version 1.0
 * @created 16-Nov-2011 10:05:24
 */
public abstract class ActiveFilter<IN, OUT> extends Filter<IN, OUT> implements
		Runnable {

	protected Push<OUT> _target;
	protected Pull<IN> _source;

	public ActiveFilter(Pull<IN> source, Push<OUT> target) {
		_target = target;
		_source = source;
	}

	/**
	 * IN data = read(); OUT temp = execute(data); write(temp);
	 */
	@Override
	public void run() {
		while (true) {
			OUT entity = createEntity();
			boolean isFull;
			do {
				isFull = execute(entity, _source.read());
			} while (!isFull);

			_target.write(entity);
		}
	}
}